'''
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License") you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http:#www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
'''
from base.graph.TripleBoundary import TripleBoundary
from base.rdf.StatementBoundary import StatementBoundary

# import org.apache.jena.graph.Triple;
# import org.apache.jena.graph.TripleBoundary;

'''
 * StatementBoundaryBase - a base class for StatementBoundarys, with
 * built-in conversation to triples and a continueWith as well as a stopAt.
'''
from abc import ABC, abstractmethod


class TripleBoundaryWithModelAndStatementBoundary(TripleBoundary):

    def __init__(self, model, statementBoundary):
        self.model = model
        self.statementBoundary = statementBoundary

    def stopAt(self, t):
        return self.statementBoundary.stopAt(self.model.asStatement(t))


class StatementBoundaryBase(ABC, StatementBoundary):
    '''
     * Method to over-ride to define what stops the boundary search default
     * definition is !continueWith(s). <i>exactly one</i> of these two methods
     * must be defined.
    '''

    # @Override
    # param Statement s
    # result boolean
    @abstractmethod
    def stopAt(self, s):
        return not self.continueWith(s)

    '''
     * Method to over-ride to define what continues the boundary search default
     * definition is !stopAt(s). <i>exactly one</i> of these two methods
     * must be defined.
    '''

    # param Statement s
    # result boolean
    # @abstractmethod
    def continueWith(self, s):
        return not self.stopAt(s)

    '''
     * Expresses this StatementBoundary as a TripleBoundary.
    '''

    # @Override
    # param Model m
    # result final TripleBoundary
    @abstractmethod
    def asTripleBoundary(self, m):
        return self.convert(m, self)

    '''
     * Answer a TripleBoundary that is implemented in terms of a StatementBoundary.
    '''

    # param final Model s, final StatementBoundary b
    # result static TripleBoundary
    @staticmethod
    def convert(s, b):
        return TripleBoundaryWithModelAndStatementBoundary(s, b)
